package com.rwlai.dianshang.domain;

import com.qunchuang.bos.BaseEntity;
import com.qunchuang.bos.BosSet;
import com.qunchuang.bos.Bostype;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by liutim on 2017/11/23.
 */
@Entity
@Table(name = "T_ORDER")
@Bostype("_06")
public class Order extends BaseEntity {


    //这样照抄，每次都一样
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "parent", orphanRemoval = true, fetch = FetchType.EAGER)
    //留意2点：修饰符private，后面要初始化一个HashSet实例，以免后续引用为null
    private Set<OrderItem> orderitems = new HashSet<>();


    //留意这里才是public，增删元素用这个，如果需要进一步的集合控制，直接使用 getItems().get()。
    public BosSet<OrderItem> getItems() {
        return new BosSet(this.orderitems, this);
    }


    public void setUserid(String userid) {
        this.userid = userid;
    }

    private String userid;


    public long getTotalPrice(){
        long result=0;
        for(OrderItem item:this.getItems().get()){
            result+=item.getProduct().getPrice()*item.getCount();
        }
        return result;
    }

    //private User user;







}

